<?php
namespace api\tv\controller;

use api\tv\controller\Base;
use think\Config;
use think\Request;
use core\tv\model\VideoCateModel;
use core\tv\model\StoreModel;

class Store extends Base
{

    /**
     * 门店信息
     */
    public function info(Request $request)
    {
        $uuid = $request->param('uuid');
        if(!$uuid){
            $this->api(400,'缺少UUID');
        }
        $store = StoreModel::getInstance()->where(['uuid' => $uuid])->find();
        //dump($store);
        if($store){
            if(!$store->status){
                $this->api(400,'门店状态未启用',$store);
            }
            $this->api(200,'获取成功',$store);
        }else{
            $this->api(401,'门店不存在或未绑定UUID');
        }
    }

    /**
     * 绑定设备UUID
     */
    public function bind(Request $request)
    {
        $phone = $request->param('phone');
        $uuid = $request->param('uuid');
        if(!$phone){
            $this->api(400,'缺少门店负责人手机号');
        }
        if(!$uuid){
            $this->api(400,'缺少UUID');
        }
        $store = StoreModel::getInstance()->where(['principal_phone' => $phone])->find();
        if(!$store){
            $this->api(400,'未找到该负责人门店信息');
        }
        if($store->uuid){
            $this->api(400,'该门店已绑定UUID');
        }
        $store->uuid = $uuid;
        if($store->save()){
            $this->api(200,'绑定UUID成功');
        }
    }
}
 